package com.qf.test.servlet;

import com.qf.test.mapper.UserMapper;
import com.qf.test.pojo.SysUsers;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

//表示这是一个servlet类
@Service
public class UserServletImpl implements UserService {
    //设置自动注入
    @Autowired
    private UserMapper userMapper;

    /**
     * 查询所有的用户并返回
     * @return
     */
    //限制只有某个权限才能访问这个方法
    @RequiresRoles( value = {"管理员"})
    @Override
    public List<SysUsers> findAll() {
        List<SysUsers> list = userMapper.findUserAll();
        return list;
    }

    @Override
    public SysUsers findUsserByName(String userName) {
        SysUsers user = userMapper.findUsserByName(userName);
        return user;
    }

    @Override
    public Set<String> findRolesByUid(int uid) {
        List<String> list = userMapper.findRolesByUid(uid);
        HashSet<String> reloSet = new HashSet<>();
        for (String str : list) {
            reloSet.add(str);
        }
        return reloSet;
    }

    @Override
    public Set<String> findPermByUid(int uid) {
        List<String> list = userMapper.findPermByUid(uid);
        HashSet<String> pernSet = new HashSet<>();
        for (String str : list) {
            pernSet.add(str);
        }
        return pernSet;
    }
}
